package com.example.demo.contrller;

import com.example.demo.contrller.data.ReturnData;
import com.example.demo.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
public class UploadController {

    @Autowired
    UploadService uploadService;
    @PostMapping("/uploadAvatar")
    //id为学生id，file是对应的头像
    public ReturnData uploadAvatar(MultipartFile file, HttpServletRequest request) throws IOException {
        String token = request.getHeader("token");
       return uploadService.uploadAvatar(file,token);
    }
    @PostMapping("/uploadFile")
    //id为学生id，file是对应的头像
    public ReturnData uploadFile(MultipartFile file,int type, HttpServletRequest request) throws IOException {
        String token = request.getHeader("token");
        return uploadService.uploadFile(file,type,token);
    }
}
